//项目路径
var project = 'http://localhost/website';

/*$(function() {
    //类目
    listCategory("", "");
});*/

//主页楼层和类目
$(function () {
    var cid = 0;//主页cid为0
    var data = getCategory();//获取类目集合的json字符串
    //*******类目nav呈现***********
    categoryNav(cid, data);

    //*******banner下方第一层显示***********************************
    $("#firstFloorName").append(data[0].cname)
    for(var i=0;i<data[0].list.length;i++){
        $("#wz-right").append(`<a class="t3" href="products.html?csid=`+data[0].list[i].id+`">`+data[0].list[i].csname+`</a>`)
    }


    //*******banner下方第一层显示结束*******************************
    console.log(data);

    for (var i = 0; i < data.length; i++) {

        //**************首页商品楼层*****************
        if (data[i].type == "0") {
            //首页商品楼层

            productsFloor(data[i].id);
        }


        //*************首页中新闻楼层************************
        if (data[i].type == "1") {
            //首页新闻楼层
            $("#fullpage").append(
                `<div class="section" id="section"` + data[i].id + `>
                        <div class="page-header">
                            <h1>` + data[i].cname + `  <small>利用大数据，制定精准营销策略，连接未来</small></h1>
                        </div>
                        <div class="container">
                            <div class="row" id="row` + data[i].id + `">
                            </div>
                        </div>
                    </div>`
            )
            newsFloor(data[i].id);
        }
    }

    //section6    合作品牌
    $("#fullpage").append(
        `<div class="section" id="section6">
            <div class="page-header">
                <h1>合作品牌 <small>优质数字媒介资源，涵盖各行各业</small></h1>
            </div>
            <div class="container">
                <div class="row">
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                    <div class="col-xs-6 col-md-3">
                        <a href="#" class="thumbnail">
                            <img src="http://www.dllingchao.com/Templates/lc2015/img/baidu.jpg" alt="...">
                        </a>
                    </div>
                </div>
            </div>
            <p>热门区域:哈尔滨网站建设、沈阳网站建设  
                    © 2019 哈尔滨迅推科技发展有限公司 ALL RIGHTS RESERVED. 辽ICP备11009804号-3  </p>
        </div>`
    )
})

//根据csid获取csName
function findCsnameByCsid(cid, csid) {
    var data = getCategory();//获取类目集合的json字符串
    for (var i = 0; i < data.length; i++) {
        if (data[i].id == cid) {
            for (var j = 0; j < data[i].list.length; j++) {
                if(data[i].list[j].id == csid){
                    return data[i].list[j].csname
                }
            }
        }
    }
}

//产品楼层产品列表
function productsFloor(cid) {
    $.ajax({
        url: project + '/product/findProductsByCid',
        dataType: 'json',
        type: 'get',
        data: {
            pageSize: 6,
            cid: cid,
            pageNow: 1
        },
        success: function (data) {
            var cname = data.categoryExt.cname  //一级类目
            var cslist = data.categoryExt.list  //二级类目集合

            //遍历楼层中新闻内容
            //1.加入外层div
            var str = ""
            str = str + ` <div class="row list">
                    <div class="col-xs-12 col-sm-12 col-md-12">
                        <h3>`+cname+`</h3>
                        <ul>
                            <li class="active"><a style="color: white" href="`+project+`/products.html?pageNow=1&cid=`+cid+`">ALL</a></li>`

            //2.中间csname显示
            for(var i=0;i<cslist.length;i++){

                str = str + `<li><img style="margin-right: 5px" src="img/ico_10.png" alt=""><a style="color: black" href="`+project+`/products.html?pageNow=1&csid=`+cslist[i].id+`">`+cslist[i].csname+`</a></li>`
            }
            //3.标签结束
            str = str +`</ul>
                    </div>
                </div>
                <div class="row">`
            $("#productsFloor").append(str)

            //2.append内层div,显示每个产品
            for (var i = 0; i < data.list.length; i++) {
                var proName = data.list[i].proName  //产品名称
                var proPicture = data.list[i].proPicture    //产品显示图片
                var csid = data.list[i].csid        //所属类目id
                var csname = findCsnameByCsid(cid,csid)
                $("#productsFloor").append(`<div class="col-xs-6 col-sm-4 col-md-4">
                        <div class="thumbnail" >
                            <img style="width:359px;height: 240px" src="http://localhost:8080/website_manager/images`+proPicture+`"
                                alt="...">
                            <div class="caption">
                                <p><a href="products.html">` + proName + `</a></p>
                                <p>类型：` + csname + `</p>
                            </div>
                        </div>
                    </div>`)

            }
            //3.append外层div结束标签
            $("#productsFloor").append(`</div><hr>`)
        }
    });

}

//新闻楼层新闻列表
function newsFloor(cid) {
    $.ajax({
        url: project + '/news/findNewsByCid',
        dataType: 'json',
        async: false,
        type: 'get',
        data: {
            pageSize: 6,
            cid: cid,
            pageNow: 1
        },
        success: function (data) {
            //遍历楼层中新闻内容
            for (var i = 0; i < data.list.length; i++) {
                var title = data.list[i].title;//标题
                var content = data.list[i].content//内容
                if (title.length > 15) {
                    title = title.substring(0, 15) + "...";
                }
                if (content.length > 30) {
                    content = content.replace(/<[^>]+>/g, "").substring(0, 30) + "...";
                }
                $("#row" + cid).append(
                    `<div class="col-xs-12 col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <div class="caption" style="width:332px;height: 125px">
                                <a href="newsinfo.html?nid=` + data.list[i].id + `" style="text-decoration:none; color:#333;">
                                <h5>` + title + `</h5>
                                <p>` + content + `</p>
                                <a href="JavaScript:;" style="text-decoration:none; color:#333;"><p>→</p></a>
                                </a>
                            </div>
                        </div>
                    </div>`);
            }
        }
    });

}

$(function () {
    $('#fullpage').fullpage({
        resize: true,
        // 轮播图下方点
        slidesNavigation: true,
        // 默认为 true 显示控制箭头
        //navigation:true,
        //autoScrolling:false,
        scrollOverflow:true,
        controlArrows: true,
        afterLoad: function (link, index) {
            /*index 序号 1开始  当前屏的序号*/
            // if(index.index==1){
            //     console.log(index.index)
            //     $('#wz-img').addClass('wz-left');
            // }else{
            //     $('#wz-img').removeClass('wz-left');
            // } 

            // $('#wz-right').eq(index.index-1).addClass('wz-right');
            //  if(index.index == 1){
            //     $.fn.fullpage.setAllowScrolling(false);
            // }
        },
        onLeave: function (origin, destination, direction) {
            //如果目标是第三节，它将不会滚动
            // if(destination.index == 4){
            //     return false;
            // }
        }
    });


    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        paginationClickable: true,
        spaceBetween: 1000,
        centeredSlides: true,
        autoplay: 3500,
        autoplayDisableOnInteraction: true,
        loop: true,
        effect: 'fade',
    });

    // var swiper = new Swiper('.swiper-section3', {
    //     pagination: '.swiper-pagination',
    //     effect: 'coverflow',
    //     grabCursor: true,
    //     centeredSlides: true,
    //     slidesPerView: 'auto',
    //     coverflow: {
    //         rotate: 50,
    //         stretch: 0,
    //         depth: 100,
    //         modifier: 1,
    //         slideShadows : true
    //     }
    // });

})


